package com.zhu.controller;

import com.zhu.pojo.Way;
import com.zhu.service.WayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WayController {
    @Autowired
    WayService wayService;

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/way/{username}")
    public List<Way> list(@PathVariable("username") String username){
        return wayService.wayList(username);
    }

    @CrossOrigin //解决跨域问题
    @PostMapping("/api/saveWay")
    public String save(@RequestBody Way way) {
        boolean flag = wayService.save(way);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @PostMapping("/api/updWay")
    public String upd(@RequestBody Way way) {
        boolean flag = wayService.upd(way);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/delWay/{id}")
    public String upd(@PathVariable("id") int id) {
        boolean flag = wayService.del(id);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/wayAdmin")
    public List<Way> list(){
        return wayService.typeListByAdmin();
    }
}

